package com.iceclean.daoImpl;

import com.iceclean.dao.PostBarFollowDao;
import com.iceclean.po.PostBarFollow;
import com.iceclean.util.JdbcUtil;

import java.util.List;

/**
 * @author : Ice'Clean
 * @date : 2021-05-11
 */
public class PostBarFollowDaoImpl implements PostBarFollowDao {
    @Override
    public PostBarFollow findPostBarFollow(int postBarId, int userId) {
        List<PostBarFollow> postBarFollowList = JdbcUtil.query("select * from t_post_bar_follow where post_bar_id = ? and user_id = ?", PostBarFollow.class, postBarId, userId);
        return postBarFollowList.size() == 0 ? null : postBarFollowList.get(0);
    }

    @Override
    public PostBarFollow findPostBarFollowById(int postBarFollowId) {
        List<PostBarFollow> postBarFollowList = JdbcUtil.query("select * from t_post_bar_follow where post_bar_follow_id = ?", PostBarFollow.class, postBarFollowId);
        return postBarFollowList.size() == 0 ? null : postBarFollowList.get(0);
    }

    @Override
    public List<PostBarFollow> findPostBarFollowByPage(int userId, int page, int num) {
        List<PostBarFollow> postBarFollowList = JdbcUtil.query("select * from t_post_bar_follow where user_id = ? limit " + (page-1)*num + "," + num, PostBarFollow.class, userId);
        return postBarFollowList.size() == 0 ? null : postBarFollowList;
    }

    @Override
    public int createPostBarFollow(PostBarFollow postBarFollow) {
        return JdbcUtil.insert("t_post_bar_follow", postBarFollow);
    }

    @Override
    public boolean cancelPostBarFollow(PostBarFollow postBarFollow) {
        return JdbcUtil.delete("t_post_bar_follow", "post_bar_follow_id=" + postBarFollow.getPostBarFollowId());
    }
}
